package leetcode;

public class _0034 {
    /**
     * 在排序数组中查找元素的第一个和最后一个位置
     */
    class Solution {
        public int lowerBround(int[] nums,int target){
            int  n= nums.length;
            int left = 0;
            int right = n-1;
            while(left<right){
                int mid = left + (right-left)/2;
                if(nums[mid]>=target){
                    right = mid-1;
                }else{
                    left = mid+1;
                }
            }
            return left;
        }
        public int[] searchRange(int[] nums, int target) {
            int start = lowerBround(nums,target);
            if(start == nums.length||nums[start]!=target){
                return new int[]{-1,-1};
            }
            int end = lowerBround(nums,target+1)-1;
            return new int[]{start,end};
        }
    }
}
